home *** CD-ROM | disk | FTP | other *** search
- on doFind input
- global findButton
- if isEnabled(findButton) then
- clearDatabase()
- activateButtonKeepActivated(findButton)
- findUserTypedTopic(input)
- enableButton(findButton)
- end if
- end
-
- on findUserTypedTopic input
- global browserTopics, browserTopLine, numVisibleTopics, browserScroll
- watchCursor()
- set searchResults to doSearch(input)
- normalCursor()
- if not voidp(searchResults) and not (searchResults = EMPTY) then
- set browserTopics to searchResults & RETURN
- set browserTopLine to 1
- setFieldText("browser", browserTopLine, numVisibleTopics, browserTopics)
- moveScrollSquareToMatchText(browserTopLine, browserScroll)
- setSearchSuccessFul(1)
- selectTopic(1)
- showSelectedTopic()
- else
- put "No topics found" into field "searchTopic"
- set the selStart to 0
- set the selEnd to 999
- put EMPTY into field "browser"
- unhiliteClickedTopic()
- setSearchSuccessFul(0)
- end if
- end
-
- on showSelectedTopic
- showTitle()
- setTopicButtons()
- showTopicText()
- updateStage()
- end
-
- on doSearch input
- if input = EMPTY then
- exit
- end if
- if (the number of words in input = 1) and not ignorableWord(word 1 of input) then
- set searchResults to searchOneTopic(input)
- return searchResults
- end if
- if (the number of words in input > 1) and containsIgnorableWords(input) then
- set newInput to removeIgnorableWords(input)
- set searchResults to doSearch(newInput)
- return searchResults
- end if
- if (the number of words in input > 1) and not containsIgnorableWords(input) then
- set containingList to []
- set numTopics to the number of words in input
- repeat with i = 1 to numTopics
- set indexCode to word i of input && "INDEX"
- if the number of cast indexCode <> -1 then
- set topicsContainingCurrentTopic to the text of cast indexCode
- repeat with j = 1 to the number of lines in topicsContainingCurrentTopic
- add(containingList, line j of topicsContainingCurrentTopic)
- end repeat
- end if
- end repeat
- sort(containingList)
- set searchResults to EMPTY
- repeat with i = 1 to count(containingList) - numTopics + 1
- set currentTopic to getAt(containingList, i)
- set containsAll to 1
- repeat with j = 1 to numTopics - 1
- if not (getAt(containingList, i + j) = currentTopic) then
- set containsAll to 0
- exit repeat
- end if
- end repeat
- if containsAll = 1 then
- put currentTopic & RETURN after searchResults
- end if
- end repeat
- return searchResults
- end if
- end
-
- on ignorableWord whichWord
- if (whichWord = "and") or (whichWord = "of") or (whichWord = "the") or (whichWord = "a") or (whichWord = "an") then
- return 1
- else
- return 0
- end if
- end
-
- on searchOneTopic topic
- set firstLetter to char 1 of topic
- set letterNum to 1
- set letterField to firstLetter && letterNum && "INDEX"
- set indexFound to 0
- repeat while the number of cast letterField <> -1
- set letterIndex to field letterField
- set topicOffset to offset("*" & topic, letterIndex)
- if topicOffset = 0 then
- set letterNum to letterNum + 1
- set letterField to firstLetter && letterNum && "INDEX"
- next repeat
- end if
- set indexFound to 1
- exit repeat
- end repeat
- if indexFound then
- set topicsFromUserInput to char topicOffset + 1 to 32000 of letterIndex
- set nextTopicOffset to offset("*", topicsFromUserInput)
- set searchResults to char 1 to nextTopicOffset - 2 of topicsFromUserInput
- set numLines to the number of lines in searchResults
- set searchResults to line 2 to numLines of searchResults
- return searchResults
- else
- end if
- end
-
- on containsIgnorableWords phrase
- repeat with i = 1 to the number of words in phrase
- if ignorableWord(word i of phrase) then
- return 1
- end if
- end repeat
- return 0
- end
-
- on removeIgnorableWords phrase
- set newPhrase to EMPTY
- repeat with i = 1 to the number of words in phrase
- if not ignorableWord(word i of phrase) then
- set newPhrase to addWordToString(word i of phrase, newPhrase)
- end if
- end repeat
- return newPhrase
- end
-
- on addWordToString whichWord, phrase
- if phrase = EMPTY then
- return whichWord
- else
- return phrase && whichWord
- end if
- end
-
- on setSearchSuccessFul val
- global searchSuccessFul
- set searchSuccessFul to val
- end
-